Series Data Structure
A Series is a one-dimensional array with an Index. Values have a dtype;
labels identify and align them. That alignment behavior is the important
difference from a plain Python list or NumPy array.
import pandas as pd
scores = pd.Series(
[91, 84, pd.NA],
index=["Ada", "Lin", "Sam"],
name="score",
dtype="Int64",
)
Mental model
scores.arrayholds the data using a pandas extension array when applicable.scores.indexholds labels; labels need not be consecutive integers.scores.namebecomes a column label in many table operations.scores.dtypecontrols representation and missing-value behavior.
Do not memorize inferred dtypes. They can depend on input and pandas version. Specify a dtype at boundaries when strings, nullable integers, booleans, or dates must have a particular representation.
Construction and alignment
Construct from a sequence when order is primary, or from a mapping when labels are primary:
left = pd.Series({"a": 10, "b": 20})
right = pd.Series({"b": 1, "c": 2})
left + right
# a -> missing, b -> 21, c -> missing
left.add(right, fill_value=0)
# a -> 10, b -> 21, c -> 2
Arithmetic aligns by label, not by physical position. This is powerful but can silently introduce missing values when indexes differ. Compare indexes or use explicit alignment when the relationship is important.
Missing values
Use isna() and notna() rather than equality comparisons. Depending on the
dtype, missingness may be represented by pd.NA, NaN, or NaT; code should
normally rely on the shared missing-data API rather than the scalar sentinel.
Boundary
Use a NumPy array when positional homogeneous computation is the whole job. Use
a Series when labels, nullable dtypes, alignment, or pandas table operations
carry meaning.